using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQFSCHL
    {
        public DataRow Convert2QFSCHL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQFSCHL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QSLMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QSLFKATALOG"] = " ".PadRight(3 ); 
         dwReturn["QSLFSCHL"] = " ".PadRight(3 ); 
         dwReturn["QSLAENZL"] = " ".PadRight(0 ); 
         dwReturn["QSLAENB"] = " ".PadRight(8 ); 
         dwReturn["QSLAEND"] = " ".PadRight(0 ); 
         dwReturn["QSLNEUB"] = " ".PadRight(8 ); 
         dwReturn["QSLNEUD"] = " ".PadRight(0 ); 
         dwReturn["QSLSTATUS"] = " ".PadRight(1 ); 
         dwReturn["QSLBEZ"] = " ".PadRight(30 ); 
         dwReturn["QSLFART"] = " ".PadRight(2 ); 
         dwReturn["QSLVGUET"] = " ".PadRight(1 ); 
         dwReturn["QSLNETTO"] = " ".PadRight(1 ); 
         dwReturn["QSLMSCHNITT"] = " ".PadRight(1 ); 
         dwReturn["QSLDOMFKT"] = " ".PadRight(1 ); 
         dwReturn["QSLFPKT"] = " ".PadRight(0 ); 
         dwReturn["QSLMSCHNAB"] = " ".PadRight(0 ); 
         dwReturn["QSLNAHT"] = " ".PadRight(1 ); 
         dwReturn["QSLTXTFEHL"] = " ".PadRight(1 ); 
         dwReturn["QSLREPBAR"] = " ".PadRight(1 ); 
         dwReturn["QSLKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["QSLKST"] = " ".PadRight(0 ); 
         dwReturn["QSLTASTEING"] = " ".PadRight(1 ); 
         dwReturn["QSLSIGNAL"] = " ".PadRight(4 ); 
         dwReturn["QSLAUTMARK"] = " ".PadRight(1 ); 
         dwReturn["QSLSYMBOL"] = " ".PadRight(2 ); 
         dwReturn["QSLFARBE"] = " ".PadRight(2 ); 
         dwReturn["QSLFILLER"] = " ".PadRight(58 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQFSCHL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQFSCHL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQFSCHL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQFSCHL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQFSCHL(dwLocal, ITXDBVERSION);
            }
            UpdateQFSCHL(dwLocal);
        }
        public void InsertQFSCHL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QFSCHL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQFSCHL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QFSCHL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QFSCHL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QFSCHL";
            Return = Result;
            return Return;
        }
        public void DeleteQFSCHL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QFSCHL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQFSCHL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QFSCHL SET "
                    +"QSLMANDANT= :QSLMANDANT,"
                    +"QSLFKATALOG= :QSLFKATALOG,"
                    +"QSLFSCHL= :QSLFSCHL,"
                    +"QSLAENZL= :QSLAENZL,"
                    +"QSLAENB= :QSLAENB,"
                    +"QSLAEND= :QSLAEND,"
                    +"QSLNEUB= :QSLNEUB,"
                    +"QSLNEUD= :QSLNEUD,"
                    +"QSLSTATUS= :QSLSTATUS,"
                    +"QSLBEZ= :QSLBEZ,"
                    +"QSLFART= :QSLFART,"
                    +"QSLVGUET= :QSLVGUET,"
                    +"QSLNETTO= :QSLNETTO,"
                    +"QSLMSCHNITT= :QSLMSCHNITT,"
                    +"QSLDOMFKT= :QSLDOMFKT,"
                    +"QSLFPKT= :QSLFPKT,"
                    +"QSLMSCHNAB= :QSLMSCHNAB,"
                    +"QSLNAHT= :QSLNAHT,"
                    +"QSLTXTFEHL= :QSLTXTFEHL,"
                    +"QSLREPBAR= :QSLREPBAR,"
                    +"QSLKSTKRS= :QSLKSTKRS,"
                    +"QSLKST= :QSLKST,"
                    +"QSLTASTEING= :QSLTASTEING,"
                    +"QSLSIGNAL= :QSLSIGNAL,"
                    +"QSLAUTMARK= :QSLAUTMARK,"
                    +"QSLSYMBOL= :QSLSYMBOL,"
                    +"QSLFARBE= :QSLFARBE,"
                    +"QSLFILLER= :QSLFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QSLMANDANT", OracleType.NVarChar).Value = dwData["QSLMANDANT"].ToString(); 
          or1.Parameters.Add("QSLFKATALOG", OracleType.NVarChar).Value = dwData["QSLFKATALOG"].ToString(); 
          or1.Parameters.Add("QSLFSCHL", OracleType.NVarChar).Value = dwData["QSLFSCHL"].ToString(); 
          or1.Parameters.Add("QSLAENZL", OracleType.NVarChar).Value = dwData["QSLAENZL"].ToString(); 
          or1.Parameters.Add("QSLAENB", OracleType.NVarChar).Value = dwData["QSLAENB"].ToString(); 
          or1.Parameters.Add("QSLAEND", OracleType.NVarChar).Value = dwData["QSLAEND"].ToString(); 
          or1.Parameters.Add("QSLNEUB", OracleType.NVarChar).Value = dwData["QSLNEUB"].ToString(); 
          or1.Parameters.Add("QSLNEUD", OracleType.NVarChar).Value = dwData["QSLNEUD"].ToString(); 
          or1.Parameters.Add("QSLSTATUS", OracleType.NVarChar).Value = dwData["QSLSTATUS"].ToString(); 
          or1.Parameters.Add("QSLBEZ", OracleType.NVarChar).Value = dwData["QSLBEZ"].ToString(); 
          or1.Parameters.Add("QSLFART", OracleType.NVarChar).Value = dwData["QSLFART"].ToString(); 
          or1.Parameters.Add("QSLVGUET", OracleType.NVarChar).Value = dwData["QSLVGUET"].ToString(); 
          or1.Parameters.Add("QSLNETTO", OracleType.NVarChar).Value = dwData["QSLNETTO"].ToString(); 
          or1.Parameters.Add("QSLMSCHNITT", OracleType.NVarChar).Value = dwData["QSLMSCHNITT"].ToString(); 
          or1.Parameters.Add("QSLDOMFKT", OracleType.NVarChar).Value = dwData["QSLDOMFKT"].ToString(); 
          or1.Parameters.Add("QSLFPKT", OracleType.NVarChar).Value = dwData["QSLFPKT"].ToString(); 
          or1.Parameters.Add("QSLMSCHNAB", OracleType.NVarChar).Value = dwData["QSLMSCHNAB"].ToString(); 
          or1.Parameters.Add("QSLNAHT", OracleType.NVarChar).Value = dwData["QSLNAHT"].ToString(); 
          or1.Parameters.Add("QSLTXTFEHL", OracleType.NVarChar).Value = dwData["QSLTXTFEHL"].ToString(); 
          or1.Parameters.Add("QSLREPBAR", OracleType.NVarChar).Value = dwData["QSLREPBAR"].ToString(); 
          or1.Parameters.Add("QSLKSTKRS", OracleType.NVarChar).Value = dwData["QSLKSTKRS"].ToString(); 
          or1.Parameters.Add("QSLKST", OracleType.NVarChar).Value = dwData["QSLKST"].ToString(); 
          or1.Parameters.Add("QSLTASTEING", OracleType.NVarChar).Value = dwData["QSLTASTEING"].ToString(); 
          or1.Parameters.Add("QSLSIGNAL", OracleType.NVarChar).Value = dwData["QSLSIGNAL"].ToString(); 
          or1.Parameters.Add("QSLAUTMARK", OracleType.NVarChar).Value = dwData["QSLAUTMARK"].ToString(); 
          or1.Parameters.Add("QSLSYMBOL", OracleType.NVarChar).Value = dwData["QSLSYMBOL"].ToString(); 
          or1.Parameters.Add("QSLFARBE", OracleType.NVarChar).Value = dwData["QSLFARBE"].ToString(); 
          or1.Parameters.Add("QSLFILLER", OracleType.NVarChar).Value = dwData["QSLFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
